-
Notifications
You must be signed in to change notification settings - Fork 3
add select, detach, reciprocal and split related tests #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive test coverage for various tensor operations in the ATen/PyTorch C++ API, specifically focusing on split, select, reciprocal, and detach operations.
Changes:
- Added tests for multiple split-related operations (split, split_with_sizes, unsafe_split, unsafe_split_with_sizes, tensor_split, hsplit, vsplit, dsplit)
- Added tests for tensor selection operations (select, select_symint)
- Added tests for reciprocal operations (reciprocal, reciprocal_, global reciprocal function)
- Added tests for tensor detach operations (detach, detach_)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| test/ops/SplitTest.cpp | Implements 16 test cases covering various split operations including basic split, split by sizes, unsafe split variants, tensor_split, and dimensional splits (hsplit, vsplit, dsplit) |
| test/ops/SelectTest.cpp | Implements 10 test cases for tensor selection operations including dimension selection, negative indexing, chained selection, and SymInt variants |
| test/ops/ReciprocalTest.cpp | Implements 5 test cases for reciprocal operations including basic reciprocal, in-place variant, various values, multi-dimensional tensors, and global function |
| test/ops/DetachTest.cpp | Implements 5 test cases for tensor detach operations including basic detach, in-place variant, modification tests, and multi-dimensional tensors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| FileManerger file(file_name); | ||
| file.createFile(); | ||
|
|
||
| // 创建大小数组 tensor(Paddle要求总和等于维度大小8) |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading comment. The comment states "创建大小数组 tensor(Paddle要求总和等于维度大小8)" (Create size array tensor, Paddle requires sum to equal dimension size 8), but tensor_split with a tensor of indices splits at those index positions, not by sizes. The indices {2, 3, 3} will split at positions 2, 3, and 3, creating splits [0:2], [2:3], [3:3] (empty), [3:8]. If this is intentional testing behavior, the comment should clarify that these are split indices, not sizes.
| // 创建大小数组 tensor(Paddle要求总和等于维度大小8) | |
| // 创建索引数组 tensor(Paddle 中常用于按大小切分且大小和为 8,这里在 PyTorch 中作为分割索引使用) |
| @@ -0,0 +1,221 @@ | |||
| #include <ATen/ATen.h> | |||
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions adding tests for masked_select, but no test file for this function is included in the changes. Either the test file is missing, or the PR description should be updated to remove the mention of masked_select.
| TEST_F(DetachTest, InplaceDetach) { | ||
| auto file_name = g_custom_param.get(); | ||
| FileManerger file(file_name); | ||
| file.createFile(); |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect file operation usage. This test uses createFile() which will overwrite the output from the previous test BasicDetach. This test should use openAppend() to append to the file, or each test should write to a completely independent file. Based on the pattern in AbsTest.cpp where only the first test uses createFile(), this should use openAppend() instead.
| file.createFile(); | |
| file.openAppend(); |
| #include <ATen/core/Tensor.h> | ||
| #include <ATen/ops/ones.h> | ||
| #include <gtest/gtest.h> | ||
| #include <torch/all.h> |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The include torch/all.h appears to be unused. This file only uses ATen APIs, and none of the code references torch namespace functions. Consider removing this unnecessary include to keep dependencies minimal.
| #include <torch/all.h> |
| at::Tensor result = test_tensor.select(1, 2); | ||
| auto file_name = g_custom_param.get(); | ||
| FileManerger file(file_name); | ||
| file.createFile(); |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect file operation usage. This test uses createFile() which will overwrite the output from the previous test SelectDim0. This test should use openAppend() to append to the file, or each test should write to a completely independent file. Based on the pattern in AbsTest.cpp where only the first test uses createFile(), this should use openAppend() instead.
| file.createFile(); | |
| file.openAppend(); |
| FileManerger file(file_name); | ||
| file.createFile(); | ||
|
|
||
| // 使用大小数组 [3, 5](总和为8,等于维度2的大小) |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading comment. The comment states "使用大小数组 [3, 5](总和为8,等于维度2的大小)" (Using size array [3, 5], sum is 8, equal to dimension 2 size), but dsplit with an array of integers splits at those index positions, not by sizes. dsplit({3, 5}) will split at indices 3 and 5, creating 3 splits: [:, :, 0:3], [:, :, 3:5], [:, :, 5:8]. The comment should clarify that these are split indices, not sizes.
| // 使用大小数组 [3, 5](总和为8,等于维度2的大小) | |
| // 在深度维度的索引 [3, 5] 处进行分割,得到三段:[0:3]、[3:5]、[5:8] |
| TEST_F(ReciprocalTest, InplaceReciprocal) { | ||
| auto file_name = g_custom_param.get(); | ||
| FileManerger file(file_name); | ||
| file.createFile(); |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect file operation usage. This test uses createFile() which will overwrite the output from the previous test BasicReciprocal. This test should use openAppend() to append to the file, or each test should write to a completely independent file. Based on the pattern in AbsTest.cpp where only the first test uses createFile(), this should use openAppend() instead.
| file.createFile(); | |
| file.openAppend(); |
新增

reciprocalreciprocal_detachdetach_selectmasked_selecttensor_splitsplitunsafe_splitsplit_with_sizesunsafe_split_with_sizeshsplitvsplitdsplit接口测试